//
//  YD3rdInfoSectionTableViewCell.m
//  IngCard
//
//  Created by kf on 2017/8/28.
//  Copyright © 2017年 IngDan. All rights reserved.
//

#import "YD3rdInfoSectionTableViewCell.h"

@implementation YD3rdInfoSectionCellDataSource

-(Class) viewClass
{
    return [YD3rdInfoSectionTableViewCell class];
}

@end

@interface YD3rdInfoSectionTableViewCell()
@property(nonatomic, strong) UIImageView *titleImageView;
@property(nonatomic, strong) UILabel *titleLabel;
@end

@implementation YD3rdInfoSectionTableViewCell

+(CGFloat)viewHeight:(YD3rdInfoSectionCellDataSource *) dataSource
{
    return dataSource.height ?: 44;
}


- (void) initSubviews
{
    [super initSubviews];
    [self.contentView addSubview:self.titleImageView];
    [self.titleImageView makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset(15);
    }];
    
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(self.titleImageView.mas_right).offset(14);
    }];
}

-(void) onViewModelChanged
{
    YD3rdInfoSectionCellDataSource *dataSource = (YD3rdInfoSectionCellDataSource *)self.dataSource;
    if (dataSource)
    {
        self.titleImageView.image = dataSource.titleImage;
        
        self.titleLabel.text = dataSource.title;
        [self.titleLabel sizeToFit];
    }
}

#pragma mark - lazy Loading


-(UIImageView *) titleImageView
{
    if (!_titleImageView)
    {
        _titleImageView = [UIImageView new];
        _titleImageView.image = UIImageMake(@"user_3rd_info_job");
        _titleImageView.contentMode = UIViewContentModeCenter;
        [_titleImageView sizeToFit];
    }
    return _titleImageView;
}

-(UILabel *) titleLabel
{
    if (!_titleLabel)
    {
        _titleLabel = [[UILabel alloc] init];
        [_titleLabel setStyle:^(UIView *target) {
            UILABELSTYLE;
            temp.text = STRING.user_3rd_guide;
            temp.font = UIRegularFontMake(17);
            temp.textColor = UIColorMake(3, 3, 3);
            temp.textAlignment = NSTextAlignmentLeft;
        }];
        [_titleLabel sizeToFit];
    }
    return _titleLabel;
}

@end

